﻿using Furion.CMS.Core;
using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Furion.CMS.Domain
{
    /// <summary>
    /// 数据字典
    /// </summary>
    [OperateRecord("数据字典")]
    public class DataDictionary : IEntity, IEntityTypeBuilder<DataDictionary>
    {
        public DataDictionary()
        {
            CreatedTime = DateTimeOffset.UtcNow;
        }

        /// <summary>
        /// 数据Key
        /// </summary>
        [MaxLength(200), Required]
        [OperateRecord("数据键", true)]
        public string DataKey { get; set; }
        /// <summary>
        /// 数据Value
        /// </summary>
        [MaxLength(200)]
        [OperateRecord("数据值")]
        public string DataValue { get; set; }
        /// <summary>
        /// 数据描述
        /// </summary>
        [MaxLength(400)]
        public string Description { get; set; }
        /// <summary>
        /// 字典类别id
        /// </summary>
        public Guid CategoryId { get; set; }
        /// <summary>
        /// 排序号
        /// </summary>
        public int SortNumber { get; set; }
        /// <summary>
        /// 字典类别
        /// </summary>
        public virtual DataDictionaryCategory Category { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTimeOffset CreatedTime { get; set; }
        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTimeOffset? UpdatedTime { get; set; }

        public void Configure(EntityTypeBuilder<DataDictionary> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            entityBuilder.UseDefaultTableNameDefine();

            entityBuilder.HasKey(k => k.DataKey);
            entityBuilder.HasIndex(i => i.DataKey);
            entityBuilder.HasIndex(i => i.CategoryId);
        }
    }
}
